package cn.kimming.wms.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.kimming.wms.dao.IBrandDAO;
import cn.kimming.wms.dao.IProductDAO;
import cn.kimming.wms.domain.Brand;
import cn.kimming.wms.domain.Product;
import cn.kimming.wms.query.QueryObject;
import cn.kimming.wms.service.IBrandService;

@Service("brandService")
public class BrandServiceImpl implements IBrandService {

	@Autowired
	private IBrandDAO brandDAO;
	@Autowired
	private IProductDAO productDAO;
	
	@Override
	public void save(Brand obj) {
		brandDAO.save(obj);
	}

	@Override
	public void update(Brand obj) {
		brandDAO.update(obj);
	}

	@Override
	public void delete(Long id) {
		List<Product> prot = productDAO.listByBrandId(id);
		for (Product p : prot) {
			p.setBrand(null);
		}
		brandDAO.delete(brandDAO.get(id));
	}

	@Override
	public Brand get(Long id) {
		return brandDAO.get(id);
	}

	@Override
	public List<Brand> list() {
		return brandDAO.list();
	}

	@Override
	public List<Brand> query(QueryObject qo) {
		return brandDAO.query(qo);
	}
}
